<?php
require_once('../includes/config.php');

$install_version = '2.0.0';

if(isset($_GET['lang']))
{
	$_POST['lang'] = $_GET['lang'];
}

if(isset($_POST['lang']))
{
	require_once('lang/lang_'.$_POST['lang'].'.php');
}

// Check to see if the script is already installed
if(isset($config['installed']))
{
	if($config['version'] == $install_version)
	{
		// Exit the script
		exit('PHPDug is already installed.');
	}
	else
	{
		header('Location: upgrade_'.$config['version'].'.php');
		exit;
	}
}

if( ini_get('safe_mode') )
{
	$safemode = 1;
}
else
{
	$safemode = 0;
}

if($safemode)
{
	if( (!file_exists('../images/thumbs')) OR (!file_exists('../images/avatars')) )
	{
		echo 'Your hosting is currently running in Safe Mode<br><Br>';
		echo 'You must manually create the following folders and chmod the directories to 0777<br><br>';
		echo 'images/<br>';
		echo 'images/thumbs/<br>';
		echo 'images/avatars<br><br><br>';
		echo 'Once you have done this <a href="index.php">click here</a> to reload this page';
		exit;
	}
}

$error = '';

// Check that their config file is writtable
if(is_writable('../includes/config.php'))
{
	// Check that their thumbs folder is writtable
	if(is_writable('../images/'))
	{
		if(!file_exists('../images/thumbs'))
		{
			mkdir('../images/thumbs/');
		}
			
		if(!file_exists('../images/avatars'))
		{
			mkdir('../images/avatars/');
		}
	
		if(!isset($_POST['lang']))
		{
			$step = 2;
		}
		else
		{
			if(!isset($_POST['DBHost']))
			{
				$step = 3;
			}
			else
			{
				// Test the connection
				if(@mysql_connect($_POST['DBHost'], $_POST['DBUser'], $_POST['DBPass']))
				{
					if(@mysql_select_db($_POST['DBName']))
					{
						if(isset($_POST['adminuser']))
						{
							if(trim($_POST['adminuser']) == '')
							{
								$step = 4;
							}
							else
							{
								$site_path = str_replace('\\','/',ereg_replace('install', '', dirname(__FILE__)));
								$site_url = "http://" . $_SERVER['HTTP_HOST'] . ereg_replace ("index.php", "", ereg_replace ("install/", "", $_SERVER['PHP_SELF']));
										
								// Content that will be written to the config file
								$content = "<?php\n";
								$content.= "\$config['db']['host'] = '".addslashes($_POST['DBHost'])."';\n";
								$content.= "\$config['db']['name'] = '".addslashes($_POST['DBName'])."';\n";
								$content.= "\$config['db']['user'] = '".addslashes($_POST['DBUser'])."';\n";
								$content.= "\$config['db']['pass'] = '".addslashes($_POST['DBPass'])."';\n";
								$content.= "\$config['db']['pre'] = '".addslashes($_POST['DBPre'])."';\n";
								$content.= "\n";
								$content.= "\$config['site_title'] = 'PHPDug';\n";
								$content.= "\$config['site_url'] = '".addslashes($site_url)."';\n";
								$content.= "\$config['site_path'] = '".addslashes($site_path)."';\n";
								$content.= "\$config['admin_email'] = '".addslashes(stripslashes($config['admin_email']))."';\n";
								$content.= "\$config['upcomtime'] = '".$config['upcomtime']."';\n";
								$content.= "\$config['usedigg'] = '0';\n";
								$content.= "\$config['vidthumb'] = '".$config['vidthumb']."';\n";
								$content.= "\$config['mod_rewrite'] = '".addslashes(stripslashes($config['mod_rewrite']))."';\n";
								$content.= "\$config['anounce_en'] = '".addslashes(stripslashes($config['anounce_en']))."';\n";
								$content.= "\$config['anounce_txt'] = '".addslashes(stripslashes($config['anounce_txt']))."';\n";
								$content.= "\$config['safe'] = '".$safemode."';\n";
								$content.= "\$config['security'] = '".$config['security']."';\n";
								$content.= "\$config['rating_mode'] = '".addslashes(stripslashes($config['rating_mode']))."';\n";
								$content.= "\$config['rating_digs'] = '".addslashes(stripslashes($config['rating_digs']))."';\n";
								$content.= "\$config['rating_days'] = '".addslashes(stripslashes($config['rating_days']))."';\n";
								$content.= "\$config['cron_type'] = '".addslashes(stripslashes($config['cron_type']))."';\n";
								$content.= "\$config['cron_time'] = '".addslashes(stripslashes($config['cron_time']))."';\n";
								$content.= "\$config['search_type'] = '".addslashes(stripslashes($config['search_type']))."';\n";
								$content.= "\$config['mailbox_en'] = '".addslashes(stripslashes($config['mailbox_en']))."';\n";
								$content.= "\$config['tags_en'] = '".addslashes(stripslashes($config['tags_en']))."';\n";
								$content.= "\$config['validation'] = '".addslashes(stripslashes($config['validation']))."';\n";
								$content.= "\n";
								$content.= "\$config['cookie_time'] = '".addslashes(stripslashes($config['cookie_time']))."';\n";
								$content.= "\$config['cookie_name'] = '".addslashes(stripslashes($config['cookie_name']))."';\n";
								$content.= "\n";
								$content.= "\$config['email']['type'] = '".addslashes(stripslashes($config['email']['type']))."';\n";
								$content.= "\$config['email']['smtp']['host'] = '".addslashes(stripslashes($config['email']['smtp']['host']))."';\n";
								$content.= "\$config['email']['smtp']['user'] = '".addslashes(stripslashes($config['email']['smtp']['user']))."';\n";
								$content.= "\$config['email']['smtp']['pass'] = '".addslashes(stripslashes($config['email']['smtp']['pass']))."';\n";
								$content.= "\n";
								$content.= "\$config['tpl_name'] = '".$config['tpl_name']."';\n";
								$content.= "\$config['version'] = '".$config['version']."';\n";
								$content.= "\$config['lang'] = '".addslashes(stripslashes($config['lang']))."';\n";
								$content.= "\$config['installed'] = '1';\n";
								$content.= "?>";
							
								// Open the includes/config.php for writting
								$handle = fopen('../includes/config.php', 'w');
								// Write the config file
								fwrite($handle, $content);
								// Close the file
								fclose($handle);
							
								// Create Admin Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."admins` (  `admin_id` int(11) unsigned NOT NULL auto_increment,  `username` varchar(40) NOT NULL default '',  `password` varchar(40) NOT NULL default '',  PRIMARY KEY  (`admin_id`));");
								// Insert Admin Details			
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."admins` VALUES (1, '".addslashes($_POST['adminuser'])."', '".addslashes(md5($_POST['adminpass']))."');");
								// Create Admin Menu table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."amenu` (  `menu_id` smallint(3) unsigned NOT NULL auto_increment,  `sort_id` smallint(3) unsigned NOT NULL default '0',  `parent_id` smallint(3) unsigned NOT NULL default '0',  `menu_title` varchar(40) NOT NULL default '',  `menu_icon` varchar(100) NOT NULL default '',  `menu_url` varchar(255) NOT NULL default '',  `menu_target` varchar(10) NOT NULL default '',  `menu_desc` varchar(100) NOT NULL default '',  PRIMARY KEY  (`menu_id`));");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(38, 0, 0, 'CONFIGURATION', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(39, 15, 38, 'SITEDET', '<img src=\"images/icons/smicon_config.gif\">', 'site_details.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(40, 10, 97, 'EDITDET', '<img src=\"images/icons/smicon_config.gif\">', 'database.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(46, 10, 38, 'DIGGCOM', '<img src=\"images/icons/smicon_digglogo.gif\">', 'usedigg.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(41, 20, 0, 'USERS', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(42, 20, 41, 'SEARCHUSER', '<img src=\"images/icons/smicon_search.gif\">', 'search_users.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(43, 10, 0, 'CATEGORIES', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(44, 0, 43, 'ADDCAT', '<img src=\"images/icons/smicon_addrule.gif\">', 'category_add.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(45, 2, 43, 'EDITCAT', '<img src=\"images/icons/smicon_editrule.gif\">', 'category_view.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(47, 30, 0, 'STORIES', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(48, 5, 47, 'SEARCHSTOR', '<img src=\"images/icons/smicon_search.gif\">', 'search_stories.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(83, 40, 0, 'ADMINS', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(84, 0, 83, 'ADDADMIN', '<img src=\"images/icons/smicon_addrule.gif\">', 'admin_add.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(85, 0, 83, 'EDITADMIN', '<img src=\"images/icons/smicon_editrule.gif\">', 'admin_view.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(86, 50, 0, 'LOGOUT', '', 'logout.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(87, 35, 0, 'CONTENT', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(88, 10, 87, 'ADDCONTENT', '<img src=\"images/icons/smicon_addrule.gif\">', 'content_add.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(89, 20, 87, 'EDITCONTENT', '<img src=\"images/icons/smicon_editrule.gif\">', 'content_edit.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(90, 20, 38, 'TEMPLATES', '<img src=\"images/icons/smicon_template.gif\">', 'template_settings.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(91, 12, 38, 'EMAILSET', '<img src=\"images/icons/smicon_config.gif\">', 'email.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(92, 14, 38, 'RATEMODE', '<img src=\"images/icons/smicon_config.gif\">', 'mode.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(93, 10, 47, 'VIEWALL', '<img src=\"images/icons/smicon_search.gif\">', 'view_stories.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(94, 30, 41, 'VIEWALL', '<img src=\"images/icons/smicon_search.gif\">', 'search_users2.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(95, 0, 47, 'COMMENTS', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(96, 10, 95, 'VIEWALL', '<img src=\"images/icons/smicon_search.gif\">', 'view_comments.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(97, 0, 38, 'DATABASE', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(98, 0, 95, 'SEARCHCOM', '<img src=\"images/icons/smicon_search.gif\">', 'search_comments.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(100, 15, 38, 'SCRIPTHEALTH', '<img src=\"images/icons/smicon_manage.gif\">', 'health.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(101, 0, 47, 'RSSFEEDS', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(102, 10, 101, 'ADDFEED', '<img src=\"images/icons/smicon_addrule.gif\">', 'feeds_add.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(103, 20, 101, 'EDITFEED', ' 	<img src=\"images/icons/smicon_editrule.gif\">', 'feeds_view.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(104, 90, 38, 'LOGVIEW', '<img src=\"images/icons/smicon_edittemplate.gif\">', 'log_viewer.php', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(105, 0, 41, 'USERGROUPS', '', '', '', '');");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."amenu` VALUES(106, 0, 105, 'EDITGROUPS', ' 	<img src=\"images/icons/smicon_editrule.gif\">', 'usergroups_view.php', '', '');");
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."html` (  `html_id` varchar(8) NOT NULL default '',  `template` tinyint(1) unsigned NOT NULL default '0',  `html_title` varchar(255) NOT NULL default '',  `html_content` text NOT NULL,  PRIMARY KEY  (`html_id`))");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."html` VALUES ('terms', 1, 'Terms and Conditions', 'Your Terms and Conditions go here, to edit this page login to your admin panel and go to Edit Content.');");
								// Create Category Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."cats` (  `cat_id` int(11) unsigned NOT NULL auto_increment,  `parent_id` int(11) unsigned NOT NULL default '0',  `cat_title` varchar(50) NOT NULL default '',  `cat_stories` int(11) unsigned NOT NULL default '0',  `cat_subs` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`cat_id`));");
								// Insert Default Categories
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."cats` VALUES (1, 0, 'Technology', 0, 0);");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."cats` VALUES (2, 0, 'Science', 0, 0);");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."cats` VALUES (3, 0, 'World & Business', 0, 0);");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."cats` VALUES (4, 0, 'Sports', 0, 0);");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."cats` VALUES (5, 0, 'Videos', 0, 0);");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."cats` VALUES (6, 0, 'Entertainment', 0, 0);");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."cats` VALUES (7, 0, 'Gaming', 0, 0);");
								// Create Comment Digs table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."cdigs` (  `comment_id` int(11) unsigned NOT NULL default '0',  `user_id` int(11) unsigned NOT NULL default '0',  `user_ip` int(11) unsigned NOT NULL default '0',  `story_id` int(11) unsigned NOT NULL default '0',  `time` int(11) unsigned NOT NULL default '0',  `dig` tinyint(1) NOT NULL default '0',  PRIMARY KEY  (`comment_id`,`user_id`,`user_ip`),  KEY `user_id` (`user_id`,`story_id`))");
								// Create Comments Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."comm` (  `comment_id` int(11) unsigned NOT NULL auto_increment,  `parent_id` int(11) unsigned NOT NULL default '0',  `story_id` int(11) unsigned NOT NULL default '0',  `user_id` int(11) unsigned NOT NULL default '0',  `user_name` varchar(50) NOT NULL default '',  `comment_desc` mediumtext NOT NULL,  `comment_time` int(11) unsigned NOT NULL default '0',  `comment_digs` mediumint(8) NOT NULL default '0',  PRIMARY KEY  (`comment_id`),  KEY `story_id` (`story_id`));");
								// Create Cronjob table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."cron` (  `story_id` int(11) unsigned NOT NULL default '0',  `digs` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`story_id`))");
								// Create Digs table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."digs` (  `story_id` int(11) unsigned NOT NULL default '0',  `user_id` int(11) unsigned NOT NULL default '0',  `user_ip` int(11) unsigned NOT NULL default '0',  `time` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`story_id`,`user_id`,`user_ip`))");
								// Create Stories Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."stories` (  `story_id` int(11) unsigned NOT NULL auto_increment,  `user_id` int(11) unsigned NOT NULL default '0', `user_name` varchar(50) NOT NULL default '',  `story_url` varchar(255) NOT NULL default '',  `story_title` varchar(255) NOT NULL default '',  `story_desc` mediumtext NOT NULL,  `story_cat` int(11) unsigned NOT NULL default '0',  `story_rating` int(11) unsigned NOT NULL default '0',  `story_digs` mediumint(8) unsigned NOT NULL default '0',  `story_buries` mediumint(8) unsigned NOT NULL default '0',  `story_time` int(11) unsigned NOT NULL default '0',  `story_comments` mediumint(8) unsigned NOT NULL default '0',  `story_last5` int(11) unsigned NOT NULL default '0',  `story_thumb` varchar(80) NOT NULL default '',  `story_prom` enum('0','1') NOT NULL default '0',  `story_prom_date` int(11) unsigned NOT NULL default '0', `story_tags` varchar(100) NOT NULL default '',  PRIMARY KEY  (`story_id`),  FULLTEXT KEY `story_title` (`story_title`,`story_desc`)) ENGINE=MyISAM;");
								// Create Users Table			
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."users` (  `user_id` int(11) unsigned NOT NULL auto_increment, `group_id` int(11) unsigned NOT NULL default '2', `status` tinyint(1) unsigned NOT NULL default '1',  `username` varchar(50) NOT NULL default '',  `password` varchar(50) NOT NULL default '',  `email` varchar(255) NOT NULL default '',  `forgot` varchar(40) NOT NULL default '',  `remember` varchar(40) NOT NULL default '',  `avatar` tinyint(1) unsigned NOT NULL default '0',  `commentst` mediumint(3) NOT NULL default '-4',  PRIMARY KEY  (`user_id`));");
								// Create Buries Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."buries` (`story_id` int(11) unsigned NOT NULL default '0',  `user_id` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`story_id`,`user_id`));");
								// Create Friends Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."friends` (`friend_id` int(11) unsigned NOT NULL auto_increment,  `user_id1` int(11) unsigned NOT NULL default '0',  `user_id2` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`friend_id`),  UNIQUE KEY `user_id1` (`user_id1`,`user_id2`))");
								// Create Feeds Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."feeds` (  `feed_id` int(11) unsigned NOT NULL auto_increment,  `feed_url` varchar(255) NOT NULL default '',  `feed_lastch` int(11) unsigned NOT NULL default '0',  `feed_cat` int(11) unsigned NOT NULL default '0',  `feed_period` int(11) unsigned NOT NULL default '0',  `feed_user` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`feed_id`))");
								// Create Log Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."logs` (  `log_id` int(11) unsigned NOT NULL auto_increment,  `log_date` int(11) unsigned NOT NULL default '0',  `log_summary` varchar(100) NOT NULL default '',  `log_details` mediumtext NOT NULL,  PRIMARY KEY  (`log_id`))");
								// Create Feed Log Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."feeds_log` (  `feed_id` int(11) unsigned NOT NULL default '0',  `feed_hash` varchar(40) NOT NULL default '',  `feed_time` int(11) unsigned NOT NULL default '0',  PRIMARY KEY  (`feed_id`,`feed_hash`))");
								// Create inbox table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."inbox` (  `message_id` int(11) unsigned NOT NULL auto_increment,  `message_from` int(11) unsigned NOT NULL default '0',  `message_to` int(11) unsigned NOT NULL default '0',  `message_date` int(11) unsigned NOT NULL default '0',  `message_subject` varchar(50) NOT NULL default '',  `message_body` mediumtext NOT NULL,  `message_read` enum('0','1') NOT NULL default '0',  PRIMARY KEY  (`message_id`),  KEY `message_from` (`message_from`),  KEY `message_to` (`message_to`))");
								// Create Settings Table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."settings` (  `setting_id` int(11) unsigned NOT NULL auto_increment,  `setting_file` varchar(100) NOT NULL default '',  `setting_title` varchar(200) NOT NULL default '',  `setting_name` varchar(100) NOT NULL default '',  `setting_type` varchar(30) NOT NULL default 'textfield',  `setting_options` mediumtext NOT NULL,  `setting_value` mediumtext NOT NULL,  `setting_display` tinyint(1) unsigned NOT NULL default '0',  PRIMARY KEY  (`setting_id`),  KEY `setting_name` (`setting_name`),  KEY `setting_file` (`setting_file`))");			
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."settings` VALUES (1, '', 'Cron Time', 'cron_time', 'hidden', '', '0', 0);");					
								// Create Tabs table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."tags` (  `tag_id` int(11) unsigned NOT NULL auto_increment, `story_id` int(11) unsigned NOT NULL default '0',  `tag_phrase` varchar(100) NOT NULL default '',  `tag_time` int(11) NOT NULL default '0',  PRIMARY KEY  (`tag_id`),  KEY `tag_phrase` (`tag_phrase`))");
								// Create usergroups table
								mysql_query("CREATE TABLE `".addslashes($_POST['DBPre'])."usergroups` (  `group_id` int(11) unsigned NOT NULL auto_increment,  `group_removable` tinyint(1) unsigned NOT NULL default '0',  `group_name` varchar(50) NOT NULL default '',  `group_dig` tinyint(1) unsigned NOT NULL default '0',  `group_cdig` tinyint(1) unsigned NOT NULL default '0',  PRIMARY KEY  (`group_id`))");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."usergroups` VALUES(1, 0, 'Guest', 0, 0);");
								mysql_query("INSERT INTO `".addslashes($_POST['DBPre'])."usergroups` VALUES(2, 0, 'Registered', 1, 1);");
								

								$step = 5;
							}
						}
						else
						{
							$step = 4;
						}
					}
					else
					{
						$error_number = mysql_errno();
					
						if($error_number == '1044')
						{
							$error = $lang['ERROR1044'];
						}
						elseif($error_number == '1046')
						{
							$error = $lang['ERROR1046'];
						}
						elseif($error_number = '1049')
						{
							$error = $lang['ERROR1049'];
						}
						else
						{
							$error = mysql_error().' - '.$error_number;
						}
						$step = 3;
					}
				}
				else
				{
					$error_number = mysql_errno();
				
					if($error_number == '1045')
					{
						$error = $lang['ERROR1045'];
					}
					elseif($error_number == '2005')
					{
						$error = $lang['ERROR2005'];
					}
					else
					{
						$error = mysql_error().' - '.$error_number;
					}
					$step = 3;
				}
			}
		}
	}
	else
	{
		$step = 1;
		$error = 'Could not write to your images folder.<br><br>Please check that you have set the chmod/permisions to 0777';
	}
}
else
{
	$step = 1;
	$error = 'Could not write to your includes/config.php file.<br><br>Please check that you have set the chmod/permisions to 0777';
}

if($step == 1)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPDug Installation</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {
	font-size: 24px;
	font-weight: bold;
}
.style2 {
	color: #003366;
	font-weight: bold;
}
.style5 {font-size: 9px}
.style12 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.style15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
.error { color:#FF0000;}
-->
</style></head>

<body>
<table width="500"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="500%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><span class="style1">PHPDug Installation</span></td>
        <td align="right" valign="bottom">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><br></td>
  </tr>
  <tr>
    <td>
	<br><br>
	<span class="error"><?php echo $error;?></span><br><br><br>
	<a href="index.php">Click here</a> once you have corrected this.<br><br><br><br><bR>
    </td>
  </tr>
  <tr>
    <td><div align="center"><span class="style5">&copy; 2008 <a href="http://www.kubelabs.com/phpdug/">Kubelabs.com</a></span></div></td>
  </tr>
</table>
</body>
</html>
<?php
}
elseif($step == 2)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPDug Installation</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {
	font-size: 24px;
	font-weight: bold;
}
.style2 {
	color: #003366;
	font-weight: bold;
}
.style5 {font-size: 9px}
-->
</style></head>

<body>
<table width="500"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="500%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><span class="style1">PHPDug Installation</span></td>
        <td align="right" valign="bottom">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><br><br><br></td>
  </tr>
  <tr>
    <td>Please select the language you would like PHPDug to use:<br><small style="color:#FF0000;">*Some parts of the installation may not be in your chosen language</small><Br>
      <br>      <table width="500"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="33%" height="140" align="left"><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td align="center"><a href="index.php?lang=english"><img src="images/flag_en.gif" alt="English" width="130" height="87" vspace="2" border="0"></a><br>
                <a href="index.php?lang=english">English</a></td>
            </tr>
          </table></td>
          <td width="33%" height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=french"><img src="images/flag_french.gif" alt="Francais" width="130" height="87" vspace="2" border="0"></a><br>
                <a href="index.php?lang=french">Fran&ccedil;ais</a></td>
            </tr>
          </table></td>
          <td width="33%" height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=german"><img src="images/flag_german.gif" alt="Deutsch" width="130" height="87" vspace="2" border="0"></a><br>
                <a href="index.php?lang=german">Deutsch</a></td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td width="33%" height="140" align="left"><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td align="center"><a href="index.php?lang=portuguese"><img src="images/flag_port.gif" alt="Portugues" width="130" height="87" vspace="2" border="0"></a><br>
                <a href="index.php?lang=portuguese">Portugu&ecirc;s</a></td>
            </tr>
          </table></td>
          <td width="33%" height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=spanish"><img src="images/flag_spanish.gif" alt="Espanol" width="130" height="87" vspace="2" border="0"></a><br>
                <a href="index.php?lang=spanish">Espa&ntilde;ol</a></td>
            </tr>
          </table></td>
          <td width="33%" height="140"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=chinese"><img src="images/flag_chinese.gif" alt="Chinese" width="130" height="87" vspace="2" border="0"></a><br>
                  <a href="index.php?lang=chinese">Chinese</a></td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=thai"><img src="images/flag_thai.gif" alt="Thai" width="130" height="87" vspace="2" border="0"></a><br>
                  <a href="index.php?lang=thai">Thai</a></td>
            </tr>
          </table></td>
          <td height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=arabic"><img src="images/flag_arabic.gif" alt="Arabic" width="130" height="87" vspace="2" border="0"></a><br>
                  <a href="index.php?lang=arabic">Arabic</a></td>
            </tr>
          </table></td>
          <td height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=dutch"><img src="images/flag_dutch.gif" alt="Dutch" width="130" height="87" vspace="2" border="0"></a><br>
                  <a href="index.php?lang=dutch">Dutch</a></td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=indonesian"><img src="images/flag_indonesian.gif" alt="Indonesian" width="130" height="87" vspace="2" border="0"></a><br>
                  <a href="index.php?lang=indonesian">Indonesian</a></td>
            </tr>
          </table></td>
          <td height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=turkish"><img src="images/flag_turkish.gif" alt="Turkish" width="130" height="87" vspace="2" border="0"></a><br>
                  <a href="index.php?lang=turkish">Turkish</a></td>
            </tr>
          </table></td>
          <td height="140" align="left"><table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center"><a href="index.php?lang=persian"><img src="images/flag_persian.gif" alt="Persian" width="130" height="87" vspace="2" border="0"></a><br>
                  <a href="index.php?lang=persian">Persian</a></td>
            </tr>
          </table></td>
        </tr>
      </table>
      <br>
      <br>
    </td>
  </tr>
  <tr>
    <td><div align="center"><span class="style5">&copy; 2008 <a href="http://www.kubelabs.com/phpdug/">Kubelabs.com</a></span></div></td>
  </tr>
</table>
</body>
</html>
<?php
}
elseif($step == 3)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPDug Installation</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {
	font-size: 24px;
	font-weight: bold;
}
.style2 {
	color: #003366;
	font-weight: bold;
}
.style5 {font-size: 9px}
.style12 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.style15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
.error { color:#FF0000;}
-->
</style></head>

<body>
<table width="500"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="500%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><span class="style1">PHPDug Installation</span></td>
        <td align="right" valign="bottom">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><br><br><br></td>
  </tr>
  <tr>
    <td><form name="form1" method="post" action="index.php" style="padding:0px;margin:0px;">
	<table border="0" cellspacing="0" cellpadding="3">
	<tr><td><?php echo $lang['MYSQLFILL'];?>: <br>
      <br>
	<?php
	if($error != '')
	{
		echo '<span class="error">'.$error.'</span><br><Br>';
	}
	?>
	</td></tr></table>
      <br>      <table border="0" cellspacing="0" cellpadding="3">
        <tr>
          <td><span class="style12"><?php echo $lang['MYSQLHOST'];?>: </span></td>
          <td><input style="width:150px;" name="DBHost" type="text" id="DBHost" value="<?php if(isset($_POST['DBHost'])){ echo $_POST['DBHost']; } ELSE { echo 'localhost'; } ?>"></td>
          <td><span class="style12">&nbsp;<a href="javascript:alert('<?php echo $lang['HOSTHELP'];?>');">(?)</a> </span></td>
        </tr>
        <tr>
          <td><span class="style12"><?php echo $lang['MYSQLUSER'];?>:</span></td>
          <td><input style="width:150px;" name="DBUser" type="text" id="DBUser" value="<?php if(isset($_POST['DBUser'])){ echo $_POST['DBUser']; } ?>"></td>
          <td><span class="style12">&nbsp;<a href="javascript:alert('<?php echo $lang['USERHELP'];?>');">(?)</a> </span></td>
        </tr>
        <tr>
          <td><span class="style12"><?php echo $lang['MYSQLPASS'];?>:</span></td>
          <td><input style="width:150px;" name="DBPass" type="password" id="DBPass" value="<?php if(isset($_POST['DBPass'])){ echo $_POST['DBPass']; } ?>"></td>
          <td><span class="style12">&nbsp;<a href="javascript:alert('<?php echo $lang['PASSHELP'];?>');">(?)</a> </span></td>
        </tr>
        <tr>
          <td><span class="style12"><?php echo $lang['MYSQLNAME'];?>: </span></td>
          <td><input style="width:150px;" name="DBName" type="text" id="DBName" value="<?php if(isset($_POST['DBName'])){ echo $_POST['DBName']; } ?>"></td>
          <td><span class="style12">&nbsp;<a href="javascript:alert('<?php echo $lang['NAMEHELP'];?>');">(?)</a> </span></td>
        </tr>
        <tr>
          <td><span class="style12"><?php echo $lang['MYSQLPRE'];?>: </span></td>
          <td><input style="width:150px;" name="DBPre" type="text" id="DBPre" value="<?php if(isset($_POST['DBPre'])){ echo $_POST['DBPre']; } else { echo 'dug_'; } ?>"></td>
          <td><span class="style12">&nbsp;<a href="javascript:alert('<?php echo $lang['PREHELP'];?>');">(?)</a> </span></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input style="width:150px;" name="Submit" type="submit" value="Next &gt;&gt;"></td>
          <td>&nbsp;</td>
        </tr>
      </table>
            <br><br><br>
			<input name="lang" type="hidden" value="<?php echo $_POST['lang'];?>">
			 </form>
    </td>
  </tr>
  <tr>
    <td><div align="center"><span class="style5">&copy; 2008 <a href="http://www.kubelabs.com/phpdug/">Kubelabs.com</a></span></div></td>
  </tr>
</table>
</body>
</html>
<?php
}
elseif($step == '4')
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPDug Installation</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {
	font-size: 24px;
	font-weight: bold;
}
.style2 {
	color: #003366;
	font-weight: bold;
}
.style5 {font-size: 9px}
.style12 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.style15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
-->
</style></head>

<body>
<table width="500"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="500%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><span class="style1">PHPDug Installation</span></td>
        <td align="right" valign="bottom">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><br></td>
  </tr>
  <tr>
    <td>
	<form name="form1" method="post" action="index.php" style="padding:0px;margin:0px;">
	      <?php echo $lang['ADMFILL'];?><br>
      <br>
      <br>      <table border="0" cellspacing="0" cellpadding="3">
        <tr>
          <td><span class="style12"><?php echo $lang['ADMUSER'];?>: </span></td>
          <td><input style="width:150px;" name="adminuser" type="text" id="adminuser" value="<?php if(isset($_POST['adminuser'])){ echo $_POST['adminuser']; } ?>"></td>
          <td><span class="style12">&nbsp;<a href="javascript:alert('<?php echo $lang['ADMUSERHELP'];?>');">(?)</a> </span></td>
        </tr>
        <tr>
          <td><span class="style12"><?php echo $lang['ADMPASS'];?>: </span></td>
          <td><input style="width:150px;" name="adminpass" type="password" id="adminpass" value="<?php if(isset($_POST['adminpass'])){ echo $_POST['adminpass']; } ?>"></td>
          <td><span class="style12">&nbsp;<a href="javascript:alert('<?php echo $lang['ADMPASSHELP'];?>');">(?)</a> </span></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input style="width:150px;" name="Submit" type="submit" value="<?php echo $lang['NEXT'];?>"></td>
          <td>&nbsp;</td>
        </tr>
      </table>
            <br>
            <br>
			<input name="DBHost" type="hidden" id="DBHost" value="<?php echo $_POST['DBHost'];?>">
			<input name="DBName" type="hidden" id="DBName" value="<?php echo $_POST['DBName'];?>">
			<input name="DBUser" type="hidden" id="DBUser" value="<?php echo $_POST['DBUser'];?>">
			<input name="DBPass" type="hidden" id="DBPass" value="<?php echo $_POST['DBPass'];?>">
			<input name="DBPre" type="hidden" id="DBPre" value="<?php echo $_POST['DBPre'];?>">
			<input name="lang" type="hidden" value="<?php echo $_POST['lang'];?>">
			</form>
    </td>
  </tr>
  <tr>
    <td><div align="center"><span class="style5">&copy; 2008 <a href="http://www.kubelabs.com/phpdug/">Kubelabs.com</a></span></div></td>
  </tr>
</table>
</body>
</html>
<?php
}
elseif($step == '5')
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPDug Installation</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {
	font-size: 24px;
	font-weight: bold;
}
.style2 {
	color: #003366;
	font-weight: bold;
}
.style5 {font-size: 9px}
.style12 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.style15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
-->
</style></head>

<body>
<table width="500"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="500%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><span class="style1">PHPDug Installation</span></td>
        <td align="right" valign="bottom">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><br></td>
  </tr>
  <tr>
    <td><?php echo $lang['THANKYOU'];?>:<br>
      <br>      
      - <a href="../index.php">Front End</a><br>
      <br>
      - <a href="../adm/">Admin</a><br>
      <br>
    </td>
  </tr>
  <tr>
    <td><div align="center"><span class="style5">&copy; 2008 <a href="http://www.kubelabs.com/phpdug/">Kubelabs.com</a></span></div></td>
  </tr>
</table>
</body>
</html>
<?php
}
?>